import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutterjc/plugin/provide/ProvideFactory.dart';
import 'package:provide/provide.dart';

void main() {
  runApp(new BlocPlugin());
}

/*
 * Provide状态管理基础
 * https://www.jianshu.com/p/cab2c1c2523f：<br/>
 * 传入的值类型： <br/>
 * 传入的值含义：<br/>
 * 是否必传 ：
 */
class BlocPlugin extends StatefulWidget {
  State<StatefulWidget> createState() {
    return new BlocPluginState();
  }
}

/*
 * 页面功能 <br/>
 */
class BlocPluginState extends State<StatefulWidget> {
  void initState() {
    super.initState();
  }

  Widget build(BuildContext context) {
    AppBar appBar = AppBar(
      leading: new IconButton(
        icon: new Icon(Icons.arrow_back),
        onPressed: () {},
      ),
      title: new Text('FlutterDesign'),
      centerTitle: true,
      actions: <Widget>[
        new Container(width: 0, height: 0),
        new Container(width: 0, height: 0),
      ],
      backgroundColor: Colors.blue,
    );

    return MaterialApp(
      home: new Scaffold(
        appBar: appBar,
        body: new Builder(builder: (BuildContext context) {
          return Column(
            children: <Widget>[
              AWidget(),
              BWidget(),
            ],
          );
        }),
        backgroundColor: Colors.white,
        bottomNavigationBar: null,
      ),
    );
  }
}

class AWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Provide<ProvideFactory>(
      builder: (context, child, counter) {
        return Container(
          margin: EdgeInsets.all(20),
          padding: EdgeInsets.all(20),
          color: Colors.green,
          child: Text("A${counter.getProvide('zcj')}"),
        );
      },
    );
  }
}

class BWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Provide.value<ProvideFactory>(context).addProvide('zcj', "你好1");
      },
      child: Container(
        margin: EdgeInsets.all(20),
        padding: EdgeInsets.all(20),
        child: Text("B"),
        color: Colors.blue,
      ),
    );
  }
}
